package com.example.springdemo.controller;
import cn.hutool.core.date.DateUtil;
import com.example.springdemo.domain.HelloWorld;
import com.example.springdemo.domain.JsonData;
import com.example.springdemo.domain.Params;
import io.swagger.v3.oas.annotations.Operation;
import org.slf4j.Logger;
import org.springframework.web.bind.annotation.*;
import com.example.springdemo.Utils.LogFileName;
import com.example.springdemo.Utils.LoggerUtils;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.time.LocalDateTime;


/**
 * @ClassName Hello
 * @Description TODO
 * @author Wenyi Luo
 * @date 22/2/21 17:36
 * @version: 1.0
 */

@RestController
@Tag(name = "操作接口",description = "操作描述")
public class Hello {
//    @Operation(summary = "返回json")
//    @RequestMapping("/hello")
//    @ResponseBody
//    public HelloWord hellWord() {
//        HelloWord helloWord=new HelloWord();
//        helloWord.setMsg("操作成功");
//        helloWord.setState(1);
//        helloWord.setData(new JsonData("Hello Word"));
//        return helloWord;
//    }

    //注入
    Logger USER = LoggerUtils.logger(LogFileName.USER);
    @Resource
    HelloWorld helloWorld;
    @Resource
    JsonData jsonData;
    @PostConstruct
    private void init() {
        helloWorld.setMsg("操作成功");
        helloWorld.setState(1);
//        helloWorld.setData(new JsonData( "hello world 热部署8082"));

        helloWorld.setData(jsonData);
        USER.info("user 业务日志测试");
    }
    @PostMapping("/hello")
    @ResponseBody
    @Operation(summary ="返回json",description = "返回json描述")
    public HelloWorld helloWord(@RequestBody Params params) {
        helloWorld.setMsg("ok");
        helloWorld.setState(1);
        jsonData.setContent("HELLO"+params.getName());
        LocalDateTime localDateTime=LocalDateTime.now();
        String sysdate= DateUtil.formatLocalDateTime(localDateTime);
        jsonData.setSysdate(sysdate);
        helloWorld.setData(jsonData);
        USER.info("user 业务日志测试");
        return helloWorld;
    }
}
